package com.jingdianjichi.user.config;



import com.jingdianjichi.changerecord.impl.RedisChangeRecordImpl;
import com.jingdianjichi.changerecord.impl.RedisDictImpl;
import com.jingdianjichi.changerecord.properties.ChangeRecordProperties;
import com.jingdianjichi.changerecord.strategy.ChangeRecordStrategy;
import com.jingdianjichi.changerecord.strategy.DictStrategy;
import lombok.RequiredArgsConstructor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * 变更记录配置类
 *
 * @author Hu_bx
 * @date 17:17 2023/9/15
 **/
@Configuration
@RequiredArgsConstructor
public class ChangeRecordConfig {

    private final StringRedisTemplate redisTemplate;

    private final ChangeRecordProperties changeRecordProperties;

    /**
     * 默认使用内存字典
     *
     * @return com.jingdianjichi.changerecord.strategy.DictStrategy
     * @author Hu_bx
     * @date 14:59 2023/9/16
     **/
    @Bean
    public DictStrategy dictStrategy() {
        return new RedisDictImpl(redisTemplate);
    }

    /**
     * 默认使用内存存储
     *
     * @return com.jingdianjichi.changerecord.strategy.DictStrategy
     * @author Hu_bx
     * @date 14:59 2023/9/16
     **/
    @Bean
    public ChangeRecordStrategy changeRecordStrategy(DictStrategy dictStrategy) {
        return new RedisChangeRecordImpl(redisTemplate, dictStrategy, changeRecordProperties);
    }

}
